<template>
  <a-modal
    title="导出确认"
    v-model="visibleEx"
    :destroyOnClose="true"
    @ok="handleExportOk"
    okText="确认导出"
    :confirmLoading="loadingEx"
    :exportApi="exportApi"
    class="export-modal"
  >
    <p>{{exportTxt}} </p>
    <date style="width: 80%;margin:15px auto;" :status="1" :value="exportTime" @change="dateExportChange"/>
  </a-modal>
</template>

<script>
import { mbwithdrawExport } from '../store/memberApi.js'
import { agwithdrawExport } from '../store/agentApi.js'
import { merwithdrawExport } from '../store/merchantApi.js'
import { merchantExport } from '../store/merchantApi.js'
import { ptwithdrawExport } from '../store/providerApi.js'
import { brwithdrawExport } from '../store/provinceApi.js'
import { rewithdrawExport } from '../store/regionApi.js'
import { merBalanceExport } from '../store/financialApi.js'

export default {
  name:'exportList',
  props: {
    exportApi:{
      type: String,
      required: true
    },
    exportTxt:{
      type: String,
      required: false,
      default: '请选择导出时间(非必选):'
    }
  },
  data () {
    return {
      visibleEx: false,
      loadingEx: false,
      exportTime: [], // 导出时间
      exportStartTime: 0,
      exportEndTime: 0
    }
  },
  methods: {
    openPop () {
      this.exportStartTime = 0
      this.exportEndTime = 0
      this.exportTime = []
      this.visibleEx = true
    },
    // 确认导出
    handleExportOk () {
      this.loadingEx = true
      console.log(this.exportApi)
      //代理商余额提现列表导出
      if (this.exportApi === 'agentWithdraw') {
        agwithdrawExport({
          start_time: this.exportStartTime || 0,
          end_time: this.exportEndTime || 0
        }).then(res => {
          this.loadingEx = false
          if (!res.error) {
            window.location.href = res.data.url
          }
          this.visibleEx = false
        }).catch(e => {
          this.loadingEx = false
        })
      } else if (this.exportApi === 'memberWithdraw') {
        // 会员余额提现列表导出
        mbwithdrawExport({
          start_time: this.exportStartTime || 0,
          end_time: this.exportEndTime || 0
        }).then(res => {
          this.loadingEx = false
          if (!res.error) {
            window.location.href = res.data.url
          }
          this.visibleEx = false
        }).catch(e => {
          this.loadingEx = false
        })
      } else if (this.exportApi === 'merchantWithdraw') {
        // 商户余额提现列表导出
        merwithdrawExport({
          start_time: this.exportStartTime || 0,
          end_time: this.exportEndTime || 0
        }).then(res => {
          this.loadingEx = false
          if (!res.error) {
            window.location.href = res.data.url
          }
          this.visibleEx = false
        }).catch(e => {
          this.loadingEx = false
        })
      } else if (this.exportApi === 'merchantList') {
        // 商户列表导出
        merchantExport({
          start_time: this.exportStartTime || 0,
          end_time: this.exportEndTime || 0
        }).then(res => {
          this.loadingEx = false
          if (!res.error) {
            window.location.href = res.data.url
          }
          this.visibleEx = false
        }).catch(e => {
          this.loadingEx = false
        })
      } else if (this.exportApi === 'partnerWithdraw') {
        // 服务商余额提现列表导出
        ptwithdrawExport({
          start_time: this.exportStartTime || 0,
          end_time: this.exportEndTime || 0
        }).then(res => {
          this.loadingEx = false
          if (!res.error) {
            window.location.href = res.data.url
          }
          this.visibleEx = false
        }).catch(e => {
          this.loadingEx = false
        })
      } else if (this.exportApi === 'provinceWithdraw') {
        // 省份公司余额提现列表导出
        brwithdrawExport({
          start_time: this.exportStartTime || 0,
          end_time: this.exportEndTime || 0
        }).then(res => {
          this.loadingEx = false
          if (!res.error) {
            window.location.href = res.data.url
          }
          this.visibleEx = false
        }).catch(e => {
          this.loadingEx = false
        })
      } else if (this.exportApi === 'regionWithdraw') {
        // 大区分公司余额提现列表导出
        rewithdrawExport({
          start_time: this.exportStartTime || 0,
          end_time: this.exportEndTime || 0
        }).then(res => {
          this.loadingEx = false
          if (!res.error) {
            window.location.href = res.data.url
          }
          this.visibleEx = false
        }).catch(e => {
          this.loadingEx = false
        })
      } else if (this.exportApi === 'capitalNumber') {
        merBalanceExport({
          start_time: this.exportStartTime || 0,
          end_time: this.exportEndTime || 0
        }).then(res => {
          this.loadingEx = false
          if (!res.error) {
            window.location.href = res.data.url
          }
          this.visibleEx = false
        }).catch(e => {
          this.loadingEx = false
        })
      }
    },
    // 导出筛选时间
    dateExportChange({ date, start_time, end_time }) {
      this.exportTime = date
      this.exportStartTime = start_time
      this.exportEndTime = end_time
    },
  }
}
</script>

<style>

</style>
